<?php
header('Content-type:text/html;charset=utf-8');
include 'class.juhe.weather.php'; //引入天气请求类
 
//接口基本信息配置
$appkey = 'e3522e7e5072c1aa605d87b2ad0404e0'; //您申请的天气查询appkey
$weather = new weather($appkey);
$citysResult = $weather->getCitys();
if($citysResult['error_code'] == 0){    //以下可根据实际业务需求，自行改写
    //////////////////////////////////////////////////////////////////////
    $citys = $citysResult['result'];
    foreach($citys as $ckey =>$c){
        echo "ID：".$c['id'].",省份：".$c['province'].",城市：".$c['city'].",区域：".$c['district']."<br>";
    }
}else{    //以下可根据实际业务需求，自行改写
    //////////////////////////////////////////////////////////////////////
    echo $citysResult['error_code'].":".$citysResult['reason'];
}


$cityWeatherResult = $weather->getWeather('苏州');
if($cityWeatherResult['error_code'] == 0){    //以下可根据实际业务需求，自行改写
    //////////////////////////////////////////////////////////////////////
    $data = $cityWeatherResult['result'];
    echo "=======当前天气实况=======<br>";
    echo "温度：".$data['sk']['temp']."    ";
    echo "风向：".$data['sk']['wind_direction']."    （".$data['sk']['wind_strength']."）";
    echo "湿度：".$data['sk']['humidity']."    ";
    echo "<br><br>";
 
    echo "=======未来几天天气预报=======<br>";
    foreach($data['future'] as $wkey =>$f){
        echo "日期:".$f['date']." ".$f['week']." ".$f['weather']." ".$f['temperature']."<br>";
    }
    echo "<br><br>";
 
    echo "=======相关天气指数=======<br>";
    echo "穿衣指数：".$data['today']['dressing_index']." , ".$data['today']['dressing_advice']."<br>";
    echo "紫外线强度：".$data['today']['uv_index']."<br>";
    echo "舒适指数：".$data['today']['comfort_index']."<br>";
    echo "洗车指数：".$data['today']['wash_index'];
    echo "<br><br>";
 
}else{
    echo $cityWeatherResult['error_code'].":".$cityWeatherResult['reason'];
}

$ipWeatherResult = $weather->getWeatherByIP('58.215.154.128');
if($ipWeatherResult['error_code'] == 0){    //以下可根据实际业务需求，自行改写
    //////////////////////////////////////////////////////////////////////
    $data = $ipWeatherResult['result'];
    echo "=======当前城市=======<br>";
    echo $data['today']['city'];
    echo "<br><br>";
    echo "=======当前天气实况=======<br>";
    echo "温度：".$data['sk']['temp']."    ";
    echo "风向：".$data['sk']['wind_direction']."    （".$data['sk']['wind_strength']."）";
    echo "湿度：".$data['sk']['humidity']."    ";
    echo "<br><br>";
 
    echo "=======未来几天天气预报=======<br>";
    foreach($data['future'] as $wkey =>$f){
        echo "日期:".$f['date']." ".$f['week']." ".$f['weather']." ".$f['temperature']."<br>";
    }
    echo "<br><br>";
 
    echo "=======相关天气指数=======<br>";
    echo "穿衣指数：".$data['today']['dressing_index']." , ".$data['today']['dressing_advice']."<br>";
    echo "紫外线强度：".$data['today']['uv_index']."<br>";
    echo "舒适指数：".$data['today']['comfort_index']."<br>";
    echo "洗车指数：".$data['today']['wash_index'];
    echo "<br><br>";
 
}else{
    echo $ipWeatherResult['error_code'].":".$ipWeatherResult['reason'];
}


$geoWeatherResult = $weather->getWeatherByGeo(116.401394,39.916042);
if($geoWeatherResult['error_code'] == 0){    //以下可根据实际业务需求，自行改写
    //////////////////////////////////////////////////////////////////////
    $data = $geoWeatherResult['result'];
    echo "=======当前城市=======<br>";
    echo $data['today']['city'];
    echo "<br><br>";
    echo "=======当前天气实况=======<br>";
    echo "温度：".$data['sk']['temp']."    ";
    echo "风向：".$data['sk']['wind_direction']."    （".$data['sk']['wind_strength']."）";
    echo "湿度：".$data['sk']['humidity']."    ";
    echo "<br><br>";
 
    echo "=======未来几天天气预报=======<br>";
    foreach($data['future'] as $wkey =>$f){
        echo "日期:".$f['date']." ".$f['week']." ".$f['weather']." ".$f['temperature']."<br>";
    }
    echo "<br><br>";
 
    echo "=======相关天气指数=======<br>";
    echo "穿衣指数：".$data['today']['dressing_index']." , ".$data['today']['dressing_advice']."<br>";
    echo "紫外线强度：".$data['today']['uv_index']."<br>";
    echo "舒适指数：".$data['today']['comfort_index']."<br>";
    echo "洗车指数：".$data['today']['wash_index'];
    echo "<br><br>";
 
}else{
    echo $geoWeatherResult['error_code'].":".$geoWeatherResult['reason'];
}


$forecastResult = $weather->getForecast("苏州");
if($forecastResult['error_code'] == 0){    //以下可根据实际业务需求，自行改写
    //////////////////////////////////////////////////////////////////////
    $data = $forecastResult['result'];
    foreach($data as $key => $d){
        echo "日期：".$d['date']." (".$d['sh']."点-".$d['eh']."点)  ".$d['weather']." ".$d['temp1']."~".$d["temp2"]."<br>";
    }
}else{    //以下可根据实际业务需求，自行改写
    //////////////////////////////////////////////////////////////////////
    echo $forecastResult['error_code'].":".$forecastResult['reason'];
}